<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item v-for="(item, index) in breadcrumbs" :key="index" :to="item.path">
      {{ item.meta?.title || item.name }}
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const breadcrumbs = ref([])

// 生成面包屑导航
const getBreadcrumb = () => {
  const matched = route.matched.filter(item => item.meta && item.meta.title)
  
  breadcrumbs.value = [{
    path: '/home',
    name: '首页'
  }]
  
  breadcrumbs.value = breadcrumbs.value.concat(matched)
}

watch(() => route.path, () => {
  getBreadcrumb()
}, { immediate: true })
</script>

<style lang="scss" scoped>
.el-breadcrumb {
  line-height: 60px;
  font-size: 14px;
}
</style> 